package Hash.Easy;

import java.util.ArrayList;
import java.util.List;

public class LC2215 {
    public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
        int[] arr1AppearanceHash = new int[2001], arr2AppearanceHash = new int[2001]; // 数字是否在数组中出现过
        final int DELTA = 1000;
        for (int num : nums1) {
            arr1AppearanceHash[num + DELTA]++;
        }
        for (int num : nums2) {
            arr2AppearanceHash[num + DELTA]++;
        }

        List<List<Integer>> ret = new ArrayList<>();
        for (int i = 0; i < 2; i++) ret.add(new ArrayList<Integer>());
        int[] arr1AddedHash = new int[2001], arr2AddedHash = new int[2001]; // 数字是否已被加入List
        for (int num : nums1) {
            if (arr2AppearanceHash[num + DELTA] <= 0) {
                if (arr1AddedHash[num + DELTA] <= 0) ret.get(0).add(num);
                arr1AddedHash[num + DELTA]++;
            }
        }
        for (int num : nums2) {
            if (arr1AppearanceHash[num + DELTA] <= 0) {
                if (arr2AddedHash[num + DELTA] <= 0) ret.get(1).add(num);
                arr2AddedHash[num + DELTA]++;
            }
        }

        return ret;
    }
}
